package com.hk.utils;

import java.util.ArrayList;
import java.util.List;

public class RankUtil {

    /**
     * 组合
     *
     * @param resultList
     * @param i          从此下标开始排列
     * @param str        ""
     * @param obj        需要组合对象
     * @param n          组合维度
     */
    public static void rank(List<String> resultList, int i, String str, Object[] obj, int n) {
        if (n == 0) {
            String string = str.substring(0, str.lastIndexOf(","));
            resultList.add(string);
            return;
        }
        if (i == obj.length) {
            return;
        }
        rank(resultList, i + 1, str + obj[i] + ",", obj, n - 1);
        rank(resultList, i + 1, str, obj, n);

    }

    public static void main(String[] args) {
        List rankedList = new ArrayList();
        String[] sss = {"a", "b","c"};
        RankUtil.rank(rankedList, 0,"", sss , 2);
        rankedList.forEach( x -> {
            System.out.println(x +"\t ==>" + x.getClass());
        });
    }
}
